﻿#include "suswidget.h"

SusWidget::SusWidget(QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags)
{
    setFixedSize(170, 20);
    //QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
    setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
    QRect   screenSize;
    screenSize = QApplication::desktop()->rect();
    setGeometry(screenSize.width()-180, screenSize.height()-70, 170, 20);
    timeEdit = new QLineEdit(this);
    timeEdit->setGeometry(rect());
    QPalette palette;
    QBrush brush(QColor(255, 255, 0, 255));
    brush.setStyle(Qt::SolidPattern);
    QBrush brush1(QColor(85, 0, 0, 255));
    brush1.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Active, QPalette::Text, brush);
    palette.setBrush(QPalette::Active, QPalette::Base, brush1);
    palette.setBrush(QPalette::Inactive, QPalette::Text, brush);
    palette.setBrush(QPalette::Inactive, QPalette::Base, brush1);
    palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Base, brush1);
    timeEdit->setPalette(palette);
    QFont font;
    font.setFamily(QString::fromUtf8("\351\273\221\344\275\223"));
    font.setBold(true);
    font.setWeight(75);
    timeEdit->setFont(font);
    timeEdit->setAlignment(Qt::AlignCenter);
    timeEdit->setText(tr("正在统计关机剩余时间..."));
    timeEdit->setReadOnly(true);
}

SusWidget::~SusWidget()
{

}


void SusWidget::SetRemainTime(const QTime &time, int type)
{
    if ( type == REMAIN_TIME )
    {
        timeEdit->setText(tr("离关机还有：") + time.toString(tr("hh时mm分ss秒")));
    }

    if ( type == TO_SHUTDOWN )
    {
        timeEdit->setText(tr("正在关机..."));
    }
    if ( type == SHUTDOWN_ERROR )
    {
        timeEdit->setText(tr("关机失败..."));
    }
}
